package airarmory.item
{
	import airarmory.define.ItemConst;
	import airarmory.orm.vo.TblItemVO;
	
	import iris.util.StringProcessor;
	
	import mx.collections.ArrayCollection;
	import mx.utils.StringUtil;
	
	public class AllakhazamItemParser extends AbstractItemParser
	{	
		public function AllakhazamItemParser(html:String, itemVo:TblItemVO):void
		{
			super(html);
			super.itemVo = itemVo;
			
			var sp:StringProcessor = new StringProcessor(html);
			
			var itemDescription:String = sp.intercept("<div class=\"wowitem wowitemlive\">", "</div>", true, true);
			
			var lst:ArrayCollection = new ArrayCollection;
			var line:String
			itemDescription = StringUtil.trim(itemDescription);
			while(true)
			{
				try
				{
					line = new StringProcessor(itemDescription).intercept(">", "<", false, false);
				}
				catch (error:Error)
				{
					break;
				}
				line = line.replace(/&nbsp;/g, " "); 
				line = StringUtil.trim(line);
				if(line != "")
					lst.addItem(line);
					
				itemDescription = itemDescription.substr(itemDescription.indexOf(">") + 1);
			}
			
			for(var i:int = 0; i < lst.length; i++)
			{
				line = lst.getItemAt(i) as String;
				if(line == "Equip:")
				{
					lst.setItemAt(line + " " + lst.getItemAt(i + 1), i);
					lst.removeItemAt(i + 1);
				}
				else if(line == "Chest(Robe)")
				{
					lst.setItemAt("Chest", i);
				}
			}
				
			this.lines = lst.source;
			
			this.parse();
			super.validate();
		}
		private function parse():void
		{
			//super.itemVo = new TblItemVO();
			
			//super.itemVo.item_name = super.lines[0];
			//super.itemVo.item_level = super.getItemLevel();
			super.itemVo.slot = super.getSlot();
			super.itemVo.type = super.getType();
			super.itemVo.is_unique = super.getIsUnique();
			super.fitProperty();
			super.fitClassByAssigned();
			super.fitClassByType(super.itemVo.type, super.itemVo.type);
			//super.itemVo.item_id = super.getItemId(super.itemVo.item_name);
			//super.itemVo.is_token = super.getIsToken(super.itemVo.item_level);
		}
	}
}